<script setup>
import { getStockStatus } from '@/api/visual/index'
import { formatHeaderData } from '@/utils/globalMethod'
import { formatMoney, defaultShortcuts, formatStatisticsData, timeStringToDecimal } from '@/utils/globalMethod'
const key = ref(1)
const stockStatusConfig = reactive({
  header: [
    formatHeaderData('状态', '#3556bd'),
    formatHeaderData('品号', '#3556bd'),
    formatHeaderData('库存', '#3556bd'),
    formatHeaderData('安全库存', '#3556bd')
  ],
  data: [],
  index: false,
  align: ['center', 'center', 'center', 'center', 'center', 'center'],
  headerBGC: 'rgba(0,0,0,0)',
  oddRowBGC: 'rgba(0,0,0,0)',
  evenRowBGC: 'rgba(0,0,0,0)',
  columnWidth: [100, 240, 100, 100],
  rowNum: 15
})

const loadData = async () => {
  const { data } = await getStockStatus()
  stockStatusConfig.data = data.map(item => {
    let zt = ''
    if (item.zt === '正常') zt = formatHeaderData('正常', 'green')
    if (item.zt === '高于') zt = formatHeaderData('高于', 'blue')
    if (item.zt === '低于') zt = formatHeaderData('低于', 'red')
    return [zt, item.ProdID, (item.CAllAmt = formatMoney(null, item.CAllAmt)), item.SafeQty]
  })
}

onMounted(loadData)
onMounted(() => {
  window.addEventListener('resize', () => {
    nextTick(() => {
      key.value++
    })
  })
})
</script>

<template>
  <div class="ps_w_h_100">
    <ps-borderbox1 style="display: flex; flex-direction: column" :key="key">
      <div class="board-title">当前成品库存信息（安全库存）</div>
      <dv-scroll-board :key="key" :config="stockStatusConfig"></dv-scroll-board>
    </ps-borderbox1>
  </div>
</template>

<style scoped lang="scss"></style>
